#!/usr/bin/env bash

function get_touchpad() {
    xinput list | grep "Touchpad" | perl -n -e'/(\w+.*)/ && print "$1\n"'
}

function get_touchpad_id() {
    get_touchpad | perl -n -e'/id=(\d+)/ && print "$1\n"'
}

function list_config() {
    for i in $(get_touchpad_id)
    do
        xinput --list-props "$i"
    done
}

function set_config() {
    for i in $(get_touchpad_id)
    do
        xinput --set-prop "$i" "libinput Natural Scrolling Enabled" 1
        xinput --set-prop "$i" "libinput Click Method Enabled" {1 1}
        xinput --set-prop "$i" "libinput Tapping Enabled" 1
    done
}

function main() {
    case "$1" in
        "configs"  ) list_configs
                     ;;
        "set"      ) set_config
                     ;;
        "list"     ) get_touchpad
                     ;;
        * | "help" ) echo -e "$HELP_TEXT"
                     ;;
    esac
}

main "$@"
echo "Done"
